home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / inmemory / test.pas < prev   
Pascal/Delphi Source File  |  1996-04-08  |  3KB  |  99 lines

  1. unit Test;
  2.  
  3. (*
  4.  
  5.   This is an exmple of how to use TInMemoryTable and TTempTable.
  6.  
  7.   WARNING! THIS CODE IS PROVIDED AS IS WITH NO GUARANTEES OF ANY KIND!
  8.   USE THIS AT YOUR OWN RISK - YOU ARE THE ONLY PERSON RESPONSIBLE FOR
  9.   ANY DAMAGE THIS CODE MAY CAUSE - YOU HAVE BEEN WARNED!
  10.  
  11.   Having got this of my chest, more about this program:
  12.  
  13.   It creates an in-memory table and then sets the DataSet property of a
  14.   DataSource control on the form to it. So the grid that you see on your
  15.   form is actually accessing an in-memory table!
  16.  
  17.   If you have the VCL source and figured out how to recompile it (it's not
  18.   hard - read the readme) then you can go into DB.PAS, change the line
  19.   in TDataSet.InternalOpen  that reads
  20.     FCanModify := (CursorProps.eOpenMode = dbiReadWrite) and
  21.     not CursorProps.bTempTable;
  22.                                to
  23.     FCanModify := (CursorProps.eOpenMode = dbiReadWrite); { and
  24.     not CursorProps.bTempTable; }
  25.   Now just change TInMemoryTable to TTempTable in the source below - and
  26.   you have a TempTable - it's just like in-memory, but has more features.
  27.  
  28.   Have Fun!
  29.  
  30.   Gregory Trubetskoy INTERNET:grisha@mira.com
  31.   http://www.mira.com/home/grisha
  32.  
  33. *)
  34.  
  35. interface
  36.  
  37. uses
  38.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  39.   Forms, Dialogs, InMem, TempTbl,StdCtrls, DBTables, Grids, DBGrids, DB;
  40.  
  41. type
  42.   TForm1 = class(TForm)
  43.     Button1: TButton;
  44.     DataSource1: TDataSource;
  45.     DBGrid1: TDBGrid;
  46.     procedure Button1Click(Sender: TObject);
  47.     procedure FormDestroy(Sender: TObject);
  48.   private
  49.     { Private declarations }
  50.   public
  51.     { Public declarations }
  52.     MyTable: TInMemoryTable;
  53.   end;
  54.  
  55. var
  56.   Form1: TForm1;
  57.  
  58. implementation
  59.  
  60. {$R *.DFM}
  61.  
  62. procedure TForm1.Button1Click(Sender: TObject);
  63. begin
  64.  
  65.   MyTable := TInMemoryTable.Create(Form1);
  66.   with MyTable do begin
  67.     try
  68.       DatabaseName := 'DBDEMOS';
  69.       { TableName can be anything - but cannot be blank or DBE will give you
  70.         an invalid parameter error }
  71.       TableName := 'xxx.db';
  72.       { add a couple of fields }
  73.       FieldDefs.Add('F1', ftString, 5, False);
  74.       FieldDefs.Add('F2', ftString, 5, False);
  75.       CreateTable;
  76.       { open the table }
  77.       Active := True;
  78.       { add a couple of records }
  79.       InsertRecord(['abc', 'def']);
  80.       InsertRecord(['abc', 'def']);
  81.       { link the grid on the form to this table }
  82.       DataSource1.DataSet := MyTable;
  83.     finally
  84. {  these lines are moved to FormDestroy
  85.       Close;
  86.       Free;      }
  87.     end;
  88.   end;
  89.  
  90. end;
  91.  
  92. procedure TForm1.FormDestroy(Sender: TObject);
  93. begin
  94.   MyTable.Close;
  95.   MyTable.Free;
  96. end;
  97.  
  98. end.
  99.